/**
 * Created by ZhouWei on 2017/7/1.
 */

$(function () {
/*    var myBox = document.getElementById('main');
    var direction;
    var slider = {
        //判断设备是否支持touch事件
        touch:('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch,
        slider:document.getElementById('main'),

        //事件
        events:{
            index:0,     //显示元素的索引
            slider:myBox,     //this为slider对象
            handleEvent:function(event){
                var self = this;     //this指events对象
                if(event.type == 'touchstart'){
                    self.start(event);
                }else if(event.type == 'touchmove'){
                    self.move(event);
                }else if(event.type == 'touchend'){
                    self.end(event);
                }
            },
            //滑动开始
            start:function(event){
                var touch = event.targetTouches[0];     //touches数组对象获得屏幕上所有的touch，取第一个touch
                startPos = {x:touch.pageX,y:touch.pageY,time:+new Date};    //取第一个touch的坐标值
                isScrolling = 0;   //这个参数判断是垂直滚动还是水平滚动
                myBox.addEventListener('touchmove',this,false);
                myBox.addEventListener('touchend',this,false);
                event.preventDefault();
            },
            //移动
            move:function(event){
                //当屏幕有多个touch或者页面被缩放过，就不执行move操作
                if(event.targetTouches.length > 1 || event.scale && event.scale !== 1) return;
                var touch = event.targetTouches[0];
                endPos = {x:touch.pageX - startPos.x,y:touch.pageY - startPos.y};
                isScrolling = Math.abs(endPos.x) < Math.abs(endPos.y) ? 1:0;    //isScrolling为1时，表示纵向滑动，0为横向滑动
                if(isScrolling === 0){
                    if(direction != "top" && Math.abs(endPos.x)>10){
                        direction = "left";
                        $("#zhuti .dataTable").css('transform', 'translate(' + (startX +endPos.x) + 'px,'+startY+'px) translateZ(0px)');
                        $("#topHengDiv table").css('transform', 'translate(' + (startX +endPos.x) + 'px,0px) translateZ(0px)');
                        $("#svg").css('transform', 'translate(' + (startX +endPos.x) + 'px,'+startY+'px) translateZ(0px)');

                        if($("#zhuti .dataTable").offset().left>20){
                            startX = 0;
                            endPos.x = 0;
                            $("#zhuti .dataTable").css('transform', 'translate(' + (startX) + 'px,'+startY+'px) translateZ(0px)');
                            $("#topHengDiv table").css('transform', 'translate(' + (startX) + 'px,0px) translateZ(0px)');
                            $("#svg").css('transform', 'translate(' + (startX) + 'px,'+startY+'px) translateZ(0px)');
                        }
                        var xxx = $("#main").width() - $(".dataTable").width();
                        if($("#zhuti .dataTable").offset().left <= xxx){
                            startX =xxx - 20;
                            $("#zhuti .dataTable").css('transform', 'translate(' + (startX) + 'px,'+startY+'px) translateZ(0px)');
                            $("#topHengDiv table").css('transform', 'translate(' + (startX) + 'px,0px) translateZ(0px)');
                            $("#svg").css('transform', 'translate(' + (startX) + 'px,'+startY+'px) translateZ(0px)');
                        }
                    }
                }else if(isScrolling == 1){
                    if(direction != "left" && Math.abs(endPos.y)>10){
                        direction = "top";
                        $("#zhuti .dataTable").css('transform', 'translate('+startX+'px,' + (startY +endPos.y) + 'px) translateZ(0px)');
                        $(".shuzhifang table").css('transform', 'translate(0px,' + (startY +endPos.y) + 'px) translateZ(0px)');
                        $("#svg").css('transform', 'translate('+startX+'px,' + (startY +endPos.y) + 'px) translateZ(0px)');
                        if($("#zhuti .dataTable").offset().top>30+topHengDivHeight){
                            startY =0;
                            endPos.y = 0;
                            $("#zhuti .dataTable").css('transform', 'translate('+startX+'px,' + (startY +endPos.y) + 'px) translateZ(0px)');
                            $(".shuzhifang table").css('transform', 'translate(0px,' + (startY +endPos.y) + 'px) translateZ(0px)');
                            $("#svg").css('transform', 'translate('+startX+'px,' + (startY +endPos.y) + 'px) translateZ(0px)');
                        }
                        var yyy = $("#main").height() - $(".dataTable").height() - topHengDivHeight;
                        if($("#zhuti .dataTable").offset().top <= $("#main").height() - $(".dataTable").height()+30){
                            startY =yyy;
                            $("#zhuti .dataTable").css('transform', 'translate('+startX+'px,' + (yyy) + 'px) translateZ(0px)');
                            $(".shuzhifang table").css('transform', 'translate(0px,' + (yyy) + 'px) translateZ(0px)');
                            $("#svg").css('transform', 'translate('+startX+'px,' + (yyy) + 'px) translateZ(0px)');
                        }
                    }
                }
            },
            //滑动释放
            end:function(event){
                var duration = +new Date - startPos.time;    //滑动的持续时间
                if(direction == "left"){
                    startX = startX +endPos.x;
                }else{
                    startY = startY +endPos.y;
                }
                direction = null;

                var yyy = $("#main").height() - $(".dataTable").height() - topHengDivHeight;
                if(startY < yyy){
                    startY =yyy;
                    $("#zhuti .dataTable").css('transform', 'translate('+startX+'px,' + (yyy) + 'px) translateZ(0px)');
                    $(".shuzhifang table").css('transform', 'translate(0px,' + (yyy) + 'px) translateZ(0px)');
                    $("#svg").css('transform', 'translate('+startX+'px,' + (yyy) + 'px) translateZ(0px)');
                }
                var xxx = $("#main").width() - $(".dataTable").width() - 20;
                if(startX < xxx){
                    startX =xxx;
                    $("#zhuti .dataTable").css('transform', 'translate(' + (startX) + 'px,'+startY+'px) translateZ(0px)');
                    $("#topHengDiv table").css('transform', 'translate(' + (startX) + 'px,0px) translateZ(0px)');
                    $("#svg").css('transform', 'translate(' + (startX) + 'px,'+startY+'px) translateZ(0px)');
                }
                //解绑事件
                myBox.removeEventListener('touchmove',this,false);
                myBox.removeEventListener('touchend',this,false);
                event.preventDefault();
            }
        },
        //初始化
        init:function(){
            var self = this;     //this指slider对象
            if(!!self.touch) self.slider.addEventListener('touchstart',self.events,false);    //addEventListener第二个参数可以传一个对象，会调用该对象的handleEvent属性
        }
    };
    slider.init();*/
    pickArea();
});
function pickArea(){
    var choiceNum = [];
    var bgRed = "radial-gradient(circle at 45px 25px, #ffb5b5,#ae0000)";
    var bgGray = "radial-gradient(circle at 45px 25px, #F0F0F0,#7B7B7B)";
    var methodArray = ["任选一","任选二","任选三","任选四","任选五",
        "任选六","任选七","任选八","选前一","选前二","选前二","选前三","选前三"];
    var objThree = {
        hundreds: "",
        decade: "",
        unit: ""
    };
    var Total = [];
    var source = "";
    var allMoney = 0;
    var res = null;

    if(localStorage.getItem("outTime")){
        $(".mianfei").text("VIP过期:"+localStorage.getItem("outTime")+"(或免费版)");
    }
    
    if($(window).width()<1079){
        bgGray = "radial-gradient(circle at 20px 10px, #F0F0F0,#7B7B7B)";
        bgRed = "radial-gradient(circle at 20px 10px, #ffb5b5,#ae0000)";
    }
    $(".pick i").click(function () {
        if($("#functionArea").css("display") == "none"||!$(".optionsList").eq(0).is(":hidden")||!$(".InterfaceColor").eq(0).is(":hidden")){
            $("#functionArea").show();
            $("#sphere").show();
            $("#bottomTable").hide();
            $("#groomNum").hide();
            $(".displayAllNumber").hide();
            $(".modalBox").hide();
            $(".optionsList").hide();
            $(".InterfaceColor").hide();
        }else{
            $("#sphere").hide();
            $(".displayAllNumber").hide();
            $(".modalBox").hide();
            $("#bottomTable").show();
            $("#groomNum").show();
            $("#functionArea").hide();
        }
    });

    $(".menuRight i").click(function () {
        if($("#functionArea").is(":hidden")||!$("#sphere").is(":hidden")){
            $("#sphere").hide();
            $("#functionArea").show();    //如果元素为隐藏,则将它显现
            $(".displayAllNumber").hide();
            $(".modalBox").hide();
            $("#bottomTable").hide();
            $("#groomNum").hide();
        }else{
            $("#functionArea").hide();     //如果元素为显现,则将其隐藏
            $("#bottomTable").show();
            $("#groomNum").show();
        }
        $(".optionsList").show();
        $(".InterfaceColor").hide()
    });

    //任选四， 加倍弹出选项
    $(".sphereFun>div>i").click(function(){
        if($(this).siblings(".choicePm").css("display") == "none"){
            $(this).siblings(".choicePm").show();
        }else{
            $(this).siblings(".choicePm").hide();
        }
    });

    //选择一个任选选项 加倍 改变界面
    $(".sphereFun>div").each(function () {
        $(this).find(".choicePm ul li").click(function(){
            var x = $(this).parent().parent().parent().index();
            if(x == 0){
                var method = $(".sphereFun>div").eq(0).find("label").html();
                $(".circle").css("background",bgGray);
                if($.inArray(method,methodArray)>=8){   //如果是组选或者直选  将这个对象清空
                    objThree.hundreds = "";
                    objThree.decade = "";
                    objThree.unit = "";
                }else{                                           //清空数组
                    choiceNum = [];
                }
                if($(this).index() >= 8){
                    $(".positionNum label").css("display","none");
                    if($(this).index() == 8){
                        $(".positionNum span").css("backgroundColor","#D4D2D5");
                        $(".positionNum span").eq(2).css("backgroundColor","#119F99");
                    }else if($(this).index()>8 && $(this).index()<11){
                        $(".positionNum span").css("backgroundColor","#D4D2D5");
                        $(".positionNum span").eq(1).css("backgroundColor","#119F99");
                    }else{
                        $(".positionNum span").css("backgroundColor","#D4D2D5");
                        $(".positionNum span").eq(0).css("backgroundColor","#119F99");
                    }
                }else{
                    $(".positionNum label").css("display","block");
                }
                $(this).parent().parent().css("display","none").siblings("label").html($(this).html().substr(0,3));

            }else if(x == 1){
                if($(this).index() == 0){//自定义
                    $(".modalBox").css("display","block");
                    $(this).parent().parent().css("display","none");
                }else{
                    if($(window).width()<1000){
                        $(".sphereFun>div").eq(1).find("label").css("fontSize","9px");
                    }
                    $(this).parent().parent().css("display","none").siblings("label").html($(this).html()).attr("value",$(this).attr("value"));
                }
            }
        });
    });

    //自定义倍数点击确定或者取消
    $(".modalBox>div>span").click(function(){
        var ex = /^\d+$/;  //判断整数
        if($(this).html() == "确定"){
            var val = $(this).siblings("input").val();
            if(!isNaN(val) && ex.test(val) && val>0){
                if(val >99){
                    if($(window).width()<1079){
                        $(".sphereFun>div").eq(1).find("label").css("fontSize","8px");
                    }else{
                        $(".sphereFun>div").eq(1).find("label").css("fontSize","14px");
                    }
                }
                $(".sphereFun>div").eq(1).find("label").html("加倍X"+val).attr("value",val);
                $(".modalBox").css("display","none");
                val = null;
            }else{
                $(".inputAlert").html("请输入大于1的整数").slideDown();
                setTimeout(function(){
                    $(".inputAlert").slideUp();
                },2000)
            }
        }else if($(this).html() == "取消"){
            $(".modalBox").css("display","none");
            val = null;
        }
    });

    //保存着百位个位和十位的所选球  并将它变成红色
    $(".positionNum span").click(function(){
        var method = $(".sphereFun>div").eq(0).find("label").html();
        if($.inArray(method,methodArray)==8 && $(this).index()<2){
            alert("只允许选择个位的一个球");
            return 0 ;
        }else if($.inArray(method,methodArray)>8 && $.inArray(method,methodArray)<11 && $(this).index()==0){
            alert("只允许选择个位和十位的两个球");
            return 0 ;
        }
        $(".positionNum span").css("backgroundColor","#D4D2D5");
        $(this).css("backgroundColor","#119F99");
        $(".circle").css("background",bgGray);
        if($(this).html() == "十位"){
            var decade = Number(objThree.decade);
            if(decade>0){
                $(".circle").css("background",bgGray);
                $(".circle").eq(decade -1).css("background",bgRed);
            }
        }else if($(this).html() == "个位"){
            var unit = Number(objThree.unit);
            if(unit>0){
                $(".circle").css("background",bgGray);
                $(".circle").eq(unit -1).css("background",bgRed);
            }
        }else{
            var hundreds = Number(objThree.hundreds);
            if(hundreds>0){
                $(".circle").css("background",bgGray);
                $(".circle").eq(hundreds -1).css("background",bgRed);
            }
        }
    });

    //点击球
    $(".stage .circle label").click(function(){
        var method = $(".sphereFun>div").eq(0).find("label").html();
        var doubleNum = $(".sphereFun>div").eq(1).find("label").html();
        if($.inArray(method,methodArray)>=8){   //如果是组选或者直选
            $(".circle").css("background",bgGray);  //先将所有球变成灰色
            if($(".positionNum span").eq(0).css("backgroundColor") == "rgb(17, 159, 153)"){ //百位
                if($(this).html() == objThree.hundreds){       //如果已经选中了  变灰 删除
                    $(this).parent().css("background",bgGray);
                    objThree.hundreds = "";
                }else{
                    $(this).parent().css("background",bgRed); //选中的球位红色 并加到对象中
                    objThree.hundreds = $(this).html();
                }
            }else if($(".positionNum span").eq(1).css("backgroundColor") == "rgb(17, 159, 153)"){ //十位
                if($(this).html() == objThree.decade){       //如果已经选中了  变灰 删除
                    $(this).parent().css("background",bgGray);
                    objThree.decade = "";
                }else{
                    $(this).parent().css("background",bgRed); //选中的球位红色 并加到对象中
                    objThree.decade = $(this).html();
                }
            }else{  //个位
                if($(this).html() == objThree.unit){       //如果已经选中了  变灰 删除
                    $(this).parent().css("background",bgGray);
                    objThree.unit = "";
                }else{
                    $(this).parent().css("background",bgRed); //选中的球位红色 并加到对象中
                    objThree.unit = $(this).html();
                }
            }
        }else{                                           //否则是任选
            if($.inArray($(this).html(),choiceNum)<0){  //如果数组中没有该球
                $(this).parent().css("background",bgRed);
                choiceNum.push($(this).html());
            }else{                                      //如果有该球
                $(this).parent().css("background",bgGray);
                choiceNum.splice(jQuery.inArray($(this).html(),choiceNum),1);
            }
        }
    });

    //点击确定
    $(".middle s").click(function(){   //点击确定后
        $(".allTotal").html("");
        $(".circle").css("background",bgGray);   //变灰

        var method = $(".sphereFun>div").eq(0).find("label").html();   //玩法
        var doubleNum = $(".sphereFun>div").eq(1).find("label").html(); //加倍
        var multiple = Number($(".sphereFun>div").eq(1).find("label").attr("value"));
        var num = "";                                  //所选号字符串
        var sAD = "复式";
        if($.inArray(method,methodArray)>=8){   //如果是组选或者直选 将全部都是单式
            sAD = "单式";
            if($.inArray(method,methodArray)==8){
                num ="  个位"+objThree.unit;
            }else if($.inArray(method,methodArray)>8 && $.inArray(method,methodArray)<11){
                num = "  十位"+objThree.decade+"  个位"+objThree.unit;
            }else{
                num = "百位"+objThree.hundreds+"  十位"+objThree.decade+"  个位"+objThree.unit;
            }
            res = method + ":"+sAD+" "+num+" "+doubleNum + " "+ multiple*2+"元";
            objThree.hundreds = "";
            objThree.decade = "";            //清空
            objThree.unit = "";
        }else{
            num = choiceNum.sort().join(" ");
            if($.inArray(method,methodArray)+1 < choiceNum.length){   //组合
                sAD = "复式";
                var m = choiceNum.length;
                var n = $.inArray(method,methodArray)+1;
                var combinationNumber = factorial(m)/(factorial(n)*(factorial(m-n)));
                multiple *= combinationNumber;
                res = method + "："+sAD+" "+num+" "+doubleNum + " "+ multiple*2+"元";
            }else if($.inArray(method,methodArray)+1 == choiceNum.length) {
                sAD = "单式";
                res = method + ":"+sAD+" "+num+" "+doubleNum + " "+ multiple*2+"元";
            }else{
                var hhh =Number($.inArray(method,methodArray))+1;
                alert("选择的球数不能少于"+hhh+"个");
                res = null;
            }
            choiceNum = [];     //清空
        }

        if(res){
            allMoney += multiple*2;
            source = "determine";   //表明来源是点击确定后  而不是点击已选
            $("#sphere").hide();
            var ppp = "<p>"+res+"</p>";
            $(".displayAllNumber").show().find(".multiLineData").append(ppp);
            Total.push(res);
        }
    });

    //点击返回 清空 复制投注号
    $(".bottomOption button").click(function(){
        if($(this).index() == 0){                 //点击返回
            if($(this).html() == "返回"){
                $("#sphere").show();
                $(".displayAllNumber").hide();
            }else{
                var clipboard = new Clipboard('.js-copy', {
                    text: function() {
                        return Total.join("\r")+"\r"+$(".allTotal").text();
                    }
                });
                //复制成功执行的回调，可选
                clipboard.on('success', function(e) {
                    $(".allTotal").html("复制成功").css("color","blue");
                    setTimeout(function () {
                        $(".allTotal").html("共 : "+ allMoney/2+"注 ， 合计 ： "+allMoney+"元").css("color","black");
                    },2000)
                });

                //复制失败执行的回调，可选
                clipboard.on('error', function(e) {
                    $(".allTotal").html("复制失败").css("color","red");
                    setTimeout(function () {
                        $(".allTotal").html("共 : "+ allMoney/2+"注 ， 合计 ： "+allMoney+"元").css("color","black");
                    },2000)
                });
                return 0;
            }
        }else{                                    //点击清空
            if(source == "determine"){            //判断来源
                Total.pop();
            }else if (source == "selected"){
                Total = [];
                $(".bottomOption>.allTotal").html("");
            }
        }
        $(".multiLineData p").remove();
    });

    //点击已选
    $(".sphereFun .last").click(function(){
        source = "selected";
        $("#sphere").hide();
        $(".displayAllNumber").show();
        $(".bottomOption>.allTotal").html("共 : "+ allMoney/2+"注 ， 合计 ： "+allMoney+"元");
        for(var i =0;i<Total.length;i++){
            var ppp = "<p>"+Total[i]+"</p>";
            $(".multiLineData").append(ppp);
        }
    });

    //分享qq好友
    $(".bottomImg >.qqShare").click(function(){
        var href = window.location.href;
        var leirong;
        var biaoti = $(".headerMiddle").text();
        if(source == "determine"){            //判断来源
            leirong = res;
        }else if (source == "selected"){
            leirong = Total.join("\r\n")+$(".allTotal").text();
        }
        var summary = leirong;
        $(this).attr("href","http://connect.qq.com/widget/shareqq/index.html?url="+href+"&showcount=0&summary="+leirong+"&desc="+leirong+"&title="+biaoti+"&site=jiathis&pics=");
    });

    //分享微信好友
    $(".winXinShare").click(function() {
        var wx = api.require('wx');
        var leirong;
        if (source == "determine") { //判断来源
            leirong = res;
        } else if (source == "selected") {
            leirong = Total.join("  ") + $(".allTotal").text();
        }
        var wx = api.require('wx');
        wx.isInstalled(function(ret, err) {
            if (ret.installed) {
                wx.shareText({
                    apiKey: '',
                    scene: 'session',
                    text: leirong
                }, function(ret, err) {
                    if (ret.status) {
                        alert('分享成功');
                    } else {
                        alert(err.code);
                    }
                });
            } else {
                alert('当前设备未安装微信客户端');
            }
        });
    });

    //点击机选
    $(".sphereFun .machineSel>s").click(function(){
        var method = $(".sphereFun>div").eq(0).find("label").html();   //玩法
        $(".sphereNum section figure").css("background",bgGray);
        choiceNum = [];
        objThree.hundreds = "";
        objThree.decade = "";            //清空
        objThree.unit = "";
        if($.inArray(method,methodArray)>=8){   //如果是组选或者直选 将全部都是单式
            if($.inArray(method,methodArray) == 8){
                var id = randUnique(1,11,1);
                $(".sphereNum section").eq(id-1).find("figure").css("background",bgRed);
                objThree.unit =id<10?id="0"+id:id;
            }else if($.inArray(method,methodArray) >9 && $.inArray(method,methodArray) <11){
                var id = randUnique(1,11,2);
                var tag;
                for(var o=1;o<3;o++){
                    if($(".positionNum span").eq(o).css("backgroundColor") == "rgb(17, 159, 153)"){
                        tag = o;
                    }
                }
                if(tag == 2){  //个位
                    tag = 0;
                }else{
                    tag = 1;
                }
                $(".sphereNum section").eq(id[tag]-1).find("figure").css("background",bgRed);
                objThree.unit =id[0]<10?id[0]="0"+id[0]:id[0];
                objThree.decade =id[1]<10?id[1]="0"+id[1]:id[1];
            }else{
                var id = randUnique(1,11,3);
                var tag;
                for(var o=0;o<3;o++){
                    if($(".positionNum span").eq(o).css("backgroundColor") == "rgb(17, 159, 153)"){
                        tag = o;
                    }
                }
                $(".sphereNum section").eq(id[tag]-1).find("figure").css("background",bgRed);
                objThree.hundreds =id[0]<10?id[0]="0"+id[0]:id[0];
                objThree.decade =id[1]<10?id[1]="0"+id[1]:id[1];
                objThree.unit =id[2]<10?id[2]="0"+id[2]:id[2];
            }
        }else{
            if($.inArray(method,methodArray) == 0){
                var id = randUnique(1,11,1);
                $(".sphereNum section").eq(id-1).find("figure").css("background",bgRed);
                choiceNum.push(id<10?id="0"+id:id);
            }else if($.inArray(method,methodArray) == 1){
                var id = randUnique(1,11,2);
                for(var i=0;i<id.length;i++){
                    $(".sphereNum section").eq(id[i]-1).find("figure").css("background",bgRed);
                    choiceNum.push(id[i]<10?id[i]="0"+id[i]:id[i]);
                }
            }else if($.inArray(method,methodArray) == 2){
                var id = randUnique(1,11,3);
                for(var i=0;i<id.length;i++){
                    $(".sphereNum section").eq(id[i]-1).find("figure").css("background",bgRed);
                    choiceNum.push(id[i]<10?id[i]="0"+id[i]:id[i]);
                }
            }else if($.inArray(method,methodArray) == 3){
                var id = randUnique(1,11,4);
                for(var i=0;i<id.length;i++){
                    $(".sphereNum section").eq(id[i]-1).find("figure").css("background",bgRed);
                    choiceNum.push(id[i]<10?id[i]="0"+id[i]:id[i]);
                }
            }else if($.inArray(method,methodArray) == 4){
                var id = randUnique(1,11,5);
                for(var i=0;i<id.length;i++){
                    $(".sphereNum section").eq(id[i]-1).find("figure").css("background",bgRed);
                    choiceNum.push(id[i]<10?id[i]="0"+id[i]:id[i]);
                }
            }else if($.inArray(method,methodArray) == 5){
                var id = randUnique(1,11,6);
                for(var i=0;i<id.length;i++){
                    $(".sphereNum section").eq(id[i]-1).find("figure").css("background",bgRed);
                    choiceNum.push(id[i]<10?id[i]="0"+id[i]:id[i]);
                }
            }else if($.inArray(method,methodArray) == 6){
                var id = randUnique(1,11,7);
                for(var i=0;i<id.length;i++){
                    $(".sphereNum section").eq(id[i]-1).find("figure").css("background",bgRed);
                    choiceNum.push(id[i]<10?id[i]="0"+id[i]:id[i]);
                }
            }else if($.inArray(method,methodArray) == 7){
                var id = randUnique(1,11,8);
                for(var i=0;i<id.length;i++){
                    $(".sphereNum section").eq(id[i]-1).find("figure").css("background",bgRed);
                    choiceNum.push(id[i]<10?id[i]="0"+id[i]:id[i]);
                }
            }
        }
    });

    //不重复随机号
    function randUnique(start, end, size){
        // 全部随机数值
        var allNums = new Array;

        // 判断获取随机数个数
        size = size ? (size > end - start ? end - start : size) : 1;

        // 生成随机数值区间数组
        for (var i = start, k = 0; i <= end; i++, k++) {
            allNums[k] = i;
        }

        // 打撒数组排序
        allNums.sort(function(){ return 0.5 - Math.random(); });

        // 获取数组从第一个开始到指定个数的下标区间
        return allNums.slice(0, size);
    }

    //递归调用 计算组合
    function factorial(n){
        return n > 1 ? n * factorial(n-1) : 1;
    }
}

function iscroll() {

    var yyy = $("#main").height() - $(".dataTable").height() - topHengDivHeight;

    //设置iscroll
    if($("#screenFull").css("display") == "none" && $(window).width()<1079){
        var win = $(window),
            scrollAreaEl = $('#zhuti'),
            leftFreezeEl = $('.shuzhifang'),
            leftTableEl = leftFreezeEl.find('table'),
            svg = $("#svg"),
            rightTableEl = $('#topHengDiv table');

        //动态计算容器最大高度
        function adjustHeight() {
            scrollAreaEl.height($(".main").height() - $("#qihao").height());
        }

        adjustHeight();
        win.on('resize', adjustHeight);

        var myScroll = new IScroll('#zhuti', {
            scrollX: true,
            scrollY: true,
            bounce:false,
            momentum:false,
            probeType: 3
        });

        var shuzhiScroll = new IScroll('.shuzhifang', {
            scrollX: false,
            scrollY: false,
            bounce:false,
            momentum:false,
            probeType: 3
        });

        //阻止默认滚动
        scrollAreaEl.on('touchmove mousewheel', function(e) {
            e.preventDefault();
        });

        if(yyy!=0){
            myScroll.scrollTo(0, yyy, 0, IScroll.utils.ease.elastic);
            shuzhiScroll.scrollTo(0, yyy, 0, IScroll.utils.ease.elastic);
            svg.css('transform', 'translate(' + 0 + 'px, ' + yyy + 'px) translateZ(0px)');
        }

        shuzhiScroll.disable();
        //固定上左表头的滚动
        myScroll.on('scroll', updatePosition);
        myScroll.on('scrollEnd', updatePosition);
        function updatePosition() {
            var b = this.x;
            var a = this.y;
            leftTableEl.css('transform', 'translate(0px, ' + a + 'px) translateZ(0px)');
            rightTableEl.css('transform', 'translate(' + b + 'px, 0px) translateZ(0px)');
            svg.css('transform', 'translate(' + b + 'px, ' + a + 'px) translateZ(0px)');
        }
    }
}










